﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using YArchitech.LIB;
using YJKRevitBase.WinForm;

namespace YJKColumnModify.ConnectColumnBream
{
	public partial class SelectLevelForm : System.Windows.Forms.Form
	{
		public SelectLevelForm(List<BreamInfo> lstInfo, WindowHandle hWndRevit)
		{
			this.InitializeComponent();
			this.BreamInfoClassify(lstInfo);
			this.AddCheckBox();
			this.m_hWndRevit = hWndRevit;
		}

		private void button4_Click(object sender, EventArgs e)
		{
			for (int i = 0; i < this.checkedListBox1.Items.Count; i++)
			{
				if (this.checkedListBox1.GetItemChecked(i) && this.m_dicLevelBreamInfo.ContainsKey(this.checkedListBox1.Items[i].ToString()))
				{
					this.m_selectBreamInfo = this.m_selectBreamInfo.Concat(this.m_dicLevelBreamInfo[this.checkedListBox1.Items[i].ToString()]).ToList<BreamInfo>();
				}
			}
		}

		private void AddCheckBox()
		{
			foreach (KeyValuePair<string, List<BreamInfo>> keyValuePair in this.m_dicLevelBreamInfo)
			{
				this.checkedListBox1.Items.Add(keyValuePair.Key);
			}
		}

		private void BreamInfoClassify(List<BreamInfo> lstInfo)
		{
			foreach (BreamInfo breamInfo in lstInfo)
			{
				if (this.m_dicLevelBreamInfo.ContainsKey(breamInfo.BreamViewPlan.Title))
				{
					this.m_dicLevelBreamInfo[breamInfo.BreamViewPlan.Title].Add(breamInfo);
				}
				else
				{
					List<BreamInfo> list = new List<BreamInfo>();
					list.Add(breamInfo);
					this.m_dicLevelBreamInfo.Add(breamInfo.BreamViewPlan.Title, list);
				}
			}
		}

		private void SelectLevelForm_Load(object sender, EventArgs e)
		{
			//base.Icon = Resource.YArchitechIcon;
		}

		private void button2_Click(object sender, EventArgs e)
		{
			for (int i = 0; i < this.checkedListBox1.Items.Count; i++)
			{
				this.checkedListBox1.SetItemChecked(i, false);
			}
		}

		private void button3_Click(object sender, EventArgs e)
		{
			for (int i = 0; i < this.checkedListBox1.Items.Count; i++)
			{
				bool value = !this.checkedListBox1.GetItemChecked(i);
				this.checkedListBox1.SetItemChecked(i, value);
			}
		}

		public List<BreamInfo> SelectBreamInfo
		{
			get
			{
				return this.m_selectBreamInfo;
			}
		}

		private void SelectLevelForm_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				base.Close();
			}
		}

		private void button1_Click_1(object sender, EventArgs e)
		{
			for (int i = 0; i < this.checkedListBox1.Items.Count; i++)
			{
				this.checkedListBox1.SetItemChecked(i, true);
			}
		}

		private void SelectAll_Click(object sender, EventArgs e)
		{
			for (int i = 0; i < this.checkedListBox1.Items.Count; i++)
			{
				this.checkedListBox1.SetItemChecked(i, true);
			}
		}

		private void NoSelectAll_Click(object sender, EventArgs e)
		{
			for (int i = 0; i < this.checkedListBox1.Items.Count; i++)
			{
				this.checkedListBox1.SetItemChecked(i, false);
			}
		}

		private void ReverseSelect_Click(object sender, EventArgs e)
		{
			for (int i = 0; i < this.checkedListBox1.Items.Count; i++)
			{
				bool value = !this.checkedListBox1.GetItemChecked(i);
				this.checkedListBox1.SetItemChecked(i, value);
			}
		}

		private void groupBox2_Enter(object sender, EventArgs e)
		{
		}

		private void hyGroupBoxBlackSide1_Enter(object sender, EventArgs e)
		{
		}

		private void panel1_Paint(object sender, PaintEventArgs e)
		{
		}

		private void disabledDoubleClickTreeView1_AfterSelect(object sender, TreeViewEventArgs e)
		{
		}

		private void groupBox1_Enter(object sender, EventArgs e)
		{
		}

		private void panel1_Paint_1(object sender, PaintEventArgs e)
		{
		}

		private void eidtListView1_SelectedIndexChanged(object sender, EventArgs e)
		{
		}

		private WindowHandle m_hWndRevit;

		private Dictionary<string, List<BreamInfo>> m_dicLevelBreamInfo = new Dictionary<string, List<BreamInfo>>();

		private List<CheckBox> m_lstCheckBox = new List<CheckBox>();

		private List<BreamInfo> m_selectBreamInfo = new List<BreamInfo>();
	}
}
